Emitted-artifact templates move out of Python source into package data; CLI command table becomes data - #99
Closed
open-coder-ai wants to merge 3 commits into
Closed
Emitted-artifact templates move out of Python source into package data; CLI command table becomes data#99open-coder-ai wants to merge 3 commits into
open-coder-ai wants to merge 3 commits into
Conversation
Every template for an emitted artifact written in another language (the CI
gate step YAML, the git-hook shim, the hook installer's dispatcher and
wrappers, the in-agent guard one-liners, the scaffold workflow/gitattributes/
guardrails/pointer block, the skills-bridge marker, and the runtime-bundle
handler sources as .py.tmpl) now lives under src/chock/data/templates/,
loaded via importlib.resources. Placeholders are inert __TOKEN__ markers
swapped by str.replace, so each file is valid in its own language as-is: a
new template-lint CI job shellchecks the shell templates and actionlints the
complete workflow template (tools hash-pinned in requirements/template-lint.txt),
and tests/test_template_data.py asserts every template is rendered, every
token round-trips between file and renderer, Python templates parse, and the
ownership markers survive. The template tree is covered by package-data
(pinned in tests/test_wheel_install.py) and by the PyInstaller spec's
existing collect_data_files("chock"); the binary smoke now greps the
rendered pointer block to prove a frozen template read.
Emitted bytes are unchanged: emitter goldens, runtime goldens, and a full
before/after artifact diff (sync + plugin build + marketplace build, 490
files) are byte-identical.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
The COMMANDS table in cli.py was data: command name, module path, optional
entry function, help or alias text. It now lives in
src/chock/data/commands.json (group -> name -> {module, fn?, help|alias_of}),
read at startup by cli.py, which builds the same lazy-import dispatch from it.
tests/test_cli_commands.py asserts every module in the table imports and
exposes its entrypoint, that each entry carries exactly one of help/alias_of,
and that chock --help matches the new byte-for-byte golden
(tests/fixtures/cli_help.txt); the help output is unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Adds the compact externalized_text hard rule beside code_comments: non-Python text and vendor facts live in data/template files read by code, __TOKEN__ placeholders swapped by str.replace, template files linted as their own language, package-data and frozen-binary coverage tested; error messages and behaviour stay in code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| optimize, policy-init, validate) are refreshed only by `chock install-skills .`, which | ||
| preserves local edits. | ||
| """ | ||
| _GITATTRIBUTES_TEMPLATE = template_text("scaffold/gitattributes") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Every template for an emitted artifact written in a non-Python language moves out of Python string literals into template files under
src/chock/data/templates/, loaded viaimportlib.resources(chock.resources.template_text/render_template/render_template_line). Placeholders are inert__TOKEN__markers swapped bystr.replace— never.format()/f-strings — so every template file is valid in its own language as-is and is linted as such. The CLI'sCOMMANDStable likewise moves tosrc/chock/data/commands.json, read bycli.py, which keeps its lazy-import dispatch. The compactexternalized_texthard rule is recorded inAGENTS.mdbesidecode_comments.Moved (17 template files):
compile/emitters/ci.pySTEP_TEMPLATE →ci/step.yaml(__POLICY_ID__,__GATE_PATH__)compile/emitters/git_hook.pySHIM_TEMPLATE →git-hook/shim.sh(__POLICY_ID__,__EVENT__)hooks/installers.pydispatcher + policy wrapper + Windows validate wrapper →hooks/*.sh(__EVENT__,__SOURCE__,__PS1_NAME__; the ownership marker is literal in the files and pinned toownership.GENERATED_MARKERby test)compile/emitters/in_agent.pyshell + PowerShell one-liners →in-agent/guard-command.{sh,ps1}(__ADAPTER__,__GUARD__)gate/runtime_bundle.pyhandler sources →runtime/*.py.tmpl(each valid Python as-is; the session-start dispatch is a second full variant rather than an unparseable indented fragment, with a test binding the two variants to differ only by the branch)scaffold/install_ci.pyworkflow YAML →scaffold/ci-workflow.yml(complete workflow;MARKERnow derives from the template's first line so the two cannot drift)scaffold/templates.pythree scaffolds,scaffold/agents_md.pypointer block,scaffold/skills_bridge.pybridge marker (survey delta beyond the dispatch inventory) →scaffold/*Byte-identity proof: emitter goldens and runtime goldens unchanged; full-artifact before/after diff (
chock sync;.chock.claude.cursor.github/hooks;chock plugin build --format all;chock marketplace build;gate-events.jsonlexcluded) — 490 files, zero bytes differ, symlink targets included.chock --helpfrozen byte-for-byte by a new golden.Guards added:
tests/test_template_data.py: every template is rendered by some renderer and vice versa (AST-derived); every__TOKEN__in a file equals the tokens its renderer supplies (both directions);.py.tmplparse as Python,.shpassbash -n, YAML parses; rendered step fragment pinned (actionlint can't lint a fragment); ownership-marker and pointer-marker derivations.template-lintjob: shellcheck over the shell templates (-s shfor the shebang-less one-liner), actionlint over the complete workflow template; tools hash-pinned viarequirements/template-lint.txt(pip-compile --generate-hashes;shellcheck-py/actionlint-pybundle the binaries, keeping CI and local runs on the same pins).data/templates/**/*added to[tool.setuptools.package-data], pinned by a derivation test intests/test_wheel_install.py(every on-disk template must be in the built wheel).commands.jsonrides the existingdata/*.jsonpattern and is pinned by the existing evidence-ledger wheel test's directory iteration.collect_data_files("chock")collects the tree (.py.tmpldeliberately not.py, whichcollect_data_filesskips); verified in-process against the spec's own collection call, plus a simulated_MEIPASSload; the CI binary smoke now greps the rendered pointer block out ofAGENTS.mdso a frozen template read is proven on every build. (A local PyInstaller build was attempted and failed in the container on an unrelated broken systemcryptographywhile PyInstaller's hook enumerated it — environmental; the CI binary job is the gate.)tests/test_cli_commands.py: every module path incommands.jsonimports and exposes its entrypoint; each entry carries exactly one ofhelp/alias_of;--helpmatches the golden.Out of scope by design: error/diagnostic message strings (they stay beside the condition that raises them — e.g.
gate/sessionstart.py's instruction text,authoring/matrix.py's usage text) and plugin posture prose (derived by C1/C3). Pre-existing chock-init packaged templates still use{{repo_name}}/.format()placeholders; converting them is follow-up, not this move.Definition of done
chock check→ 0 errors, 0 warnings, 0 infoschock check --only matrixpasses; matrix updated in this PR if behavior changed (no behavior change)chock sync --repo . --checkclean (compiled artifacts match their manifests)chock check --only verifyclean (lockfile matches packs and compiled artifacts)pytest -qgreen (1047 passed); new checks have attack + ordinary-data tests (token mismatch, orphan template, marker drift all assert; ordinary renders pinned)pytest acceptance/ -c acceptance/pytest.ini --rootdir=acceptancegreen (21 passed; packaging changed)ruff check .andruff format --check .cleanClaims
INSTALLED_SURFACES, the coverage table, anddocs/enforcement-surfaces.mdare untouched and still agree.🤖 Generated with Claude Code
Generated by Claude Code